package com.geekyang.rabbitmqapi.exchange.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author geekyang
 * @date 2018/10/8 21:18
 */
public class ProducerDirectExchange {

    public static void main(String[] args) throws IOException, TimeoutException {

        // 1.创建 ConnectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("39.106.128.50");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        // 2.创建 Connection
        Connection connection = connectionFactory.newConnection();

        // 3.创建 Channel
        Channel channel = connection.createChannel();

        // 4.声明
        String exchangeName = "test_direct_exchange";
        String routingKey = "test.direct";

        // 5.发送
        String msg = "Hello World RabbitMQ Direct Exchange Message ...";
        channel.basicPublish(exchangeName, routingKey, null, msg.getBytes());

    }

}
